<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>派报工报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="queryInfo.factoryname+'派报工报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="派工时间:">
          <el-date-picker v-model="queryInfo.dispatchdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="报工时间:">
          <el-date-picker v-model="queryInfo.reportdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="检验时间:">
          <el-date-picker v-model="queryInfo.checkdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item prop='engineno' label="发动机号:">
          <el-autocomplete v-model.trim="queryInfo.engineno" placeholder="请输入发动机号" :trigger-on-focus="false"
            :fetch-suggestions="getEngineNoAsync" :value-key="'engineno'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            :fetch-suggestions="getMfgordernameAsync" :value-key="'mfgordername'" :debounce="500" style="width:240px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containerno' label="任务单号:">
          <el-autocomplete v-model.trim="queryInfo.containerno" placeholder="请输入任务单号" :trigger-on-focus="false"
            :fetch-suggestions="getContainerNoAsync" :value-key="'containerno'" :debounce="500" style="width:260px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="部件号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入部件号" :trigger-on-focus="false"
            :fetch-suggestions="getProductnameAsync" :value-key="'productname'" :debounce="500" style="width:140px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="阶段:">
          <el-input v-model.trim="queryInfo.workflowstepname" placeholder="请输入" clearable style="width:120px;">
          </el-input>
        </el-form-item>

        <el-form-item label="组:">
          <el-input v-model.trim="queryInfo.teamname" placeholder="请输入" clearable style="width:120px;"></el-input>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择" clearable filterable style="width:120px;">
            <el-option v-for="p in productfamilyList" :key="p.productfamilyname" :label="p.productfamilyname"
              :value="p.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="操作" width="90">
          <template slot-scope="scope">
            <el-link @click="showDetail(scope.row)" type="primary">查看明细</el-link>
          </template>
        </el-table-column>
        <el-table-column label="批次id" prop="containerid" width="160" v-if="false"></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="160" show-overflow-tooltip></el-table-column>
        <el-table-column label="发动机号" prop="attributevalue"></el-table-column>
        <el-table-column label="物料描述" prop="productdesc" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="机型" prop="productfamilyname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="分厂计划月份" prop="factorystardate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="任务单号" prop="containerno" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="阶段" prop="workflowstepname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="部件件号" prop="bujian" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="部件名称" prop="bujiandesc" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="计划开始时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="计划结束时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>

      <!-- 明细 -->
      <el-dialog :title="detail.title" :width="'98%'" :top="'10px'" :visible.sync="detail.dialogVisiable"
        :center="true">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="工序" prop="workflowstepname" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column label="工步" prop="description" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column label="组" prop="teamname" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column label="计划开始时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="计划结束时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="派工操作人" prop="dispatcher" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="派工时间" prop="dispatchdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="派工给工人" prop="toperson" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="报工人" prop="worker" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="报工时间" prop="workdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="检验人" prop="checker" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="检验时间" prop="checkdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="超期报工原因" prop="reasondesc" show-overflow-tooltip></el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="detail.queryInfo.currentPage"
          :page-sizes="[detail.queryInfo.pageSize]" :page-size="detail.queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="detail.total">
        </el-pagination>
      </el-dialog>

    </div>
  </div>
  <script type="module">
    import { fetchSuggestion, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getFactoryInfo, getProductFamily } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryname: '',
          dispatchdate: '',
          reportdate: '',
          checkdate: '',
          engineno: '',
          mfgordername: '',
          containerno: '',//任务单
          productname: '',//部件
          workflowstepname: '',//阶段
          teamname: '',//组
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        productfamilyList: [],
        detail: {
          dialogVisiable: false,
          queryInfo: { containerid: '', currentPage: 1, pageSize: 12 },
          dataList: [], total: 0, title: ''
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询发动机号
        getEngineNoAsync(value, callback) {
          fetchSuggestion({ actionName: 'getEngineNoAsync', name: 'engineno', value, callback });
        },
        // 查询订单号
        getMfgordernameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询任务单号
        getContainerNoAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainerNoAsync', name: 'containerno', value, callback });
        },
        // 查询部件
        getProductnameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        //查询数据
        async getData(currentpage) {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/ZSDispatchReport.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg);
          }
          this.dataList = data;
          this.total = total;
        },
        // 查询明细
        showDetail(row) {
          this.detail.dialogVisiable = true;
          this.detail.title = `任务单:${row.containerno}明细`;
          this.detail.queryInfo.currentPage = 1;
          this.detail.queryInfo.containerid = row.containerid;
          this.getDetail();
        },
        async getDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/ZSDispatchReport.ashx?action=getDetail', {
            type: 'getDetail',
            ...this.queryInfo,
            ...this.detail.queryInfo
          })

          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg);
          }
          this.detail.dataList = data;
          this.detail.total = total;
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        handleDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.getDetail();
        },
      },
      async mounted() {
        const startOfWeek = dayjs().startOf('week').format('YYYY-MM-DD');
        const endOfWeek = dayjs().endOf('week').format('YYYY-MM-DD');
        this.queryInfo.dispatchdate = [startOfWeek, endOfWeek];
        const factoryid = Decrypt(getParams('factoryid'));
        const factoryInfo = await getFactoryInfo({ factoryid, isMapping: '是' });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        document.title = factoryname + '派报工报表';
        this.productfamilyList = await getProductFamily();
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>